package net.huashitong.synthetical.student.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.student.entity.DemoStudent;
import net.huashitong.synthetical.student.filter.DemoStudentFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName DemoStudentDao
 * @Description 学生信息Dao
 * @Author LK
 * @Date 2019/6/4 15:12
 * @Version V1.0
 **/
@Repository
public class DemoStudentDao extends StringDao<DemoStudent> {

    public List<DemoStudent> query(DemoStudentFilter filter) {
        GenericQuery query = createQuery("obj");
        return query.listResult(filter);
    }

    public List<DemoStudent> queryByCondition(DemoStudentFilter filter) {
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getSno()))
            query.append(" and sno like :sno").setParam("sno", "%" + filter.getSno() + "%");
        if (StringUtils.isNotBlank(filter.getName()))
            query.append(" and name = :name").setParam("name", filter.getName());
        if (StringUtils.isNotBlank(filter.getGender()))
            query.append(" and gender = :gender").setParam("gender", filter.getGender());
        if (StringUtils.isNotBlank(filter.getBirthdayStart()))
            query.append(" and birthday >= :birthdayStart").setParam("birthdayStart", filter.getBirthdayStart());
        if (StringUtils.isNotBlank(filter.getBirthdayEnd()))
            query.append(" and birthday <= :birthdayEnd").setParam("birthdayEnd", filter.getBirthdayEnd());
        return query.listResult(filter);
    }

}
